package com.sunny.t1;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String in = scanner.next();
        int sum1 = 0;
        int sum2 = 0;
        int[] data1 = new int[3];
        int[] bu1 = new int[3];
        int[] data2 = new int[3];
        int[] bu2 = new int[3];
        for(int i=0;i<in.length();i++){
            if(i<3){
                data1[i] = in.charAt(i)-'0';
                bu1[i] = 9 - data1[i];
                sum1 += data1[i];
            }else{
                data2[i-3] = in.charAt(i)-'0';
                bu2[i-3] = 9 - data2[i-3];
                sum2 += data2[i-3];
            }
        }
        Arrays.sort(data1);
        Arrays.sort(data2);
        Arrays.sort(bu1);
        Arrays.sort(bu2);
        int diff = Math.abs(sum1-sum2);
        int res;
        if(0 == diff){
            res = 0;
        }else{
            res = getRes(sum1, sum2, diff, data1, bu1, data2,bu2);
        }
        System.out.println(res);


    }

    public static int getRes(int sum1, int sum2, int diff, int[] data1, int[] bu1, int[] data2, int[] bu2){
        if(sum1 > sum2){
            if(data1[2] >= diff){
                return 1;
            }else if(bu2[2] >= diff){
                return 1;
            }else if(data1[2]+bu2[2] >= diff){
                return 2;
            }else if(data1[2] + data1[1] >= diff){
                return 2;
            }else if(bu2[2] + bu2[1] >= diff){
                return 2;
            }else{
                return 3;
            }
        }else{
            if(data2[2] >= diff){
                return 1;
            }else if(bu1[2] >= diff){
                return 1;
            }else if(data2[2] + bu1[2] >= diff){
                return 2;
            }else if(data2[2] + data2[1] >= diff){
                return 2;
            }else if(bu1[2] + bu1[1] >= diff){
                return 2;
            }else{
                return 3;
            }
        }
    }

}
